  import Diagnose from '../services/diagnose.js'
import Result from '../utils/result.js'

const diagnoseController = {
  async addMedicalRecord(req, res) {
    if (!req.body.patientid) {
      return res.status(400).json(Result.error('缺少必要参数'));
    }
    try {
      const result = await Diagnose.addMedicalRecord(req.body);
      return res.status(200).json(result);
    } catch (error) {
      console.error('添加病例失败:', error);
      return res.status(500).json(Result.error('服务器内部错误'));
    }
  },
  async getMedicalRecord(req, res) {
    try {
      const data = await Diagnose.getMedicalRecord(req.params.patientid);
      return res.status(200).json(data);
    } catch (error) {
      return res.status(500).json(error);
    }
  },
  async delMedicalRecord(req, res) {
    try {
      const data = await Diagnose.delMedicalRecord(req.body.id);
      return res.status(200).json(data);
    } catch(error) {
      return res.status(500).json(error);
    };
  },
  async addMedication(req, res) {
    try {

      const result = await Diagnose.addMedication(req.body);
      return res.status(200).json(result);
    } catch(error) {
      return res.status(500).json(error);
    };
  },
  async getMedication(req, res) {
    try {
      const data = await Diagnose.getMedication(req.params.userId);
      return res.status(200).json(data);
    }  catch(error) {
      return res.status(500).json(error);
    };
  },
  async delMedication(req, res) {
    try {
      const data = await Diagnose.delMedication(req.body.id);
      return res.status(200).json(data);
    }  catch(error) {
      return res.status(500).json(error);
    };
  },

}


export default diagnoseController;